//
//  DDLoginACK.m
//  MyClouds
//
//  Created by sarah doo on 13-8-11.
//  Copyright (c) 2013年 sarah doo. All rights reserved.
//

#import "DDLoginACK.h"

@implementation DDLoginACK



- (id)initWithData:(NSData *)data {
    self = [super initWithData:data];
    return self;
}

- (id)initWithResult:(int)result{
    self = [super init];
    if(self){
        [self setCmd:CloudCmd_LoginAck];
        [self setResult:result];
        [self setLength:(HEADER_LENGTH + 4)];
        [self setCrc:[self crcs:entity withLength:(HEADER_LENGTH + 4)]];
    }
    return self;
}

- (int)getResult
{
    NSRange range;
    range.location = HEADER_LENGTH;
    range.length = 4;
    NSData* resultData = [entity subdataWithRange:range];
    
    int result;
    [resultData getBytes:&result length:sizeof(result)];
    return result;
}

- (void)setResult:(int)result{
    NSData* resultData = [NSData dataWithBytes:&result length:sizeof(result)];
    NSRange range;
    range.location = HEADER_LENGTH;
    range.length = 4;
    [entity replaceBytesInRange:range withBytes:[resultData bytes]];
}


@end
